<?php

/**
 * @author 
 * @copyright 2008
 */
$show="index";
$table=PFX."articles";
$per_page=5;
$lim_from=$from*$per_page;
if(isset($_REQUEST['obj_id']))
{
	$obj_id=intval($_REQUEST['obj_id']);
	$show="item";
}
if($show=="index")
{
	$items=$db->fetch_array("SELECT SQL_CALC_FOUND_ROWS * FROM $table ORDER BY time DESC LIMIT $lim_from,$per_page");
	if($items!=false)
	{
		foreach($items as $k=>$v)
		{
			if($v['image']=='1')
			{
				$sizes=@getimagesize(ROOT_DIR.UPLOAD.$page['dir']."/".$v['id']."_small.jpg");
				if($sizes!=false)
				{
					$items[$k]['photo']=UPLOAD.$page['dir']."/".$v['id'];
				}
				else $items[$k]['photo']=false;
			}
			else $items[$k]['photo']=false;
		}
		$quantity = $db->fetch_one(QUANTITY);
		if($quantity[0]>0)
		{
			$smarty->assign("kolvo",$quantity[0]);
			$smarty->assign("items",$items);
			if($quantity[0]>$per_page)
			{
				$per_page_navigation = ceil($quantity[0]/$per_page);
				$smarty->assign("ppn",$per_page_navigation);
			}
		}
	}
}
elseif($show=="item")
{
	$item=$db->fetch_one("SELECT * FROM $table WHERE id='".$obj_id."'");
	if($item!=false)
	{
		if($item['image']=='1')
		{
			$sizes=@getimagesize(ROOT_DIR.UPLOAD.$page['dir']."/".$item['id']."_small.jpg");
			if($sizes!=false)
			{
				$item['photo']=UPLOAD.$page['dir']."/".$item['id'];
			}
			else $item['photo']=false;
		}
		else $item['photo']=false;
		$smarty->assign("item",$item);
		$page['template']="item";
	}
}


?>